package com.example.templateapp.util

import android.content.Context
import android.content.Intent
import com.wildma.pictureselector.FileUtils
import com.wildma.pictureselector.PictureBean
import com.wildma.pictureselector.PictureSelector
import top.zibin.luban.Luban
import top.zibin.luban.OnCompressListener

object PicCompressUtil {
    fun compressImg(data: Intent, context: Context, listener: OnCompressListener) {
        val picBean: PictureBean? = data.getParcelableExtra(PictureSelector.PICTURE_RESULT)

        if (picBean != null) {
            Luban.with(context)
                .load(picBean.path)
                .ignoreBy(100)
                .setTargetDir(FileUtils.getImageCacheDir(context))
                .setCompressListener(listener).launch()
        }
    }
}